﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NIKE_Project.BLL;
using NIKE_Project.DAL;

namespace NIKE_Project
{
    public partial class ChangesPwd : Form
    {
        //引用DBHelper类
        DBHelper db = new DBHelper();
        SignInServer signInServer = new SignInServer();
        public ChangesPwd()
        {
            InitializeComponent();
        }
       
        //修改密码功能
        private void button1_Click(object sender, EventArgs e)
        {
            var userName = textBox1.Text;
            var oldpwd = textBox2.Text;
            var newpwd = textBox3.Text;
            if(userName == null || userName == ""|| oldpwd == null || oldpwd == "" || newpwd == null || newpwd == "")
            {
                MessageBox.Show("请填写完整用户名、旧密码、新密码！");
                return;
            }
            else
            {
                if (oldpwd == newpwd)
                {
                    MessageBox.Show("旧密码与新密码不能相同！");
                    return;
                }else
                {
                    DataSet ds = signInServer.SqlUseMethod(userName);
                    //判断用户名是否正确
                    if (ds.Tables["nike"].Rows.Count == 0)
                    {
                        MessageBox.Show("该用户不存在！", "修改失败：", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    try
                    {
                        signInServer.SqlupdateMethod(userName, oldpwd, newpwd);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("修改失败！");
                    }
                    MessageBox.Show("修改成功！");
                    this.Close();

                }
            }
        }
        //取消按钮
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
